package com.dyz.leetcode._13_binaryTree;


import com.dyz.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class _144_preorderTraversal {
    private List<Integer> res = new ArrayList<>();
    public List<Integer> preorderTraversal(TreeNode root) {
        if(root==null){return res;}
        inOrder(root);
        return res;
    }

    private void inOrder(TreeNode root){
        if(root==null){return;}
        res.add(root.val);
        if(root.left!=null){inOrder(root.left);}
        if(root.right!=null){inOrder(root.right);}
    }
}
